package com.thinkgem.jeesite.modules.ship.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.ship.entity.ShipIllegal;
import com.thinkgem.jeesite.modules.ship.service.ShipIllegalService;

/**
 * 船舶违法信息Controller
 * @author lgx
 * @version 2016-04-16
 */
@Controller
@RequestMapping(value = "${adminPath}/ship/shipIllegal")
public class ShipIllegalController extends BaseController {

	@Autowired
	private ShipIllegalService shipIllegalService;
	
	@ModelAttribute
	public ShipIllegal get(@RequestParam(required=false) String id) {
		ShipIllegal entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = shipIllegalService.get(id);
		}
		if (entity == null){
			entity = new ShipIllegal();
		}
		return entity;
	}
	
	@RequiresPermissions("ship:shipIllegal:view")
	@RequestMapping(value = {"shipIllegalList", ""})
	public String list(ShipIllegal shipIllegal, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ShipIllegal> page = shipIllegalService.findPage(new Page<ShipIllegal>(request, response), shipIllegal); 
		model.addAttribute("page", page);
		return "modules/ship/shipIllegalList";
	}

	@RequiresPermissions("ship:shipIllegal:view")
	@RequestMapping(value = "shipIllegalForm")
	public String form(ShipIllegal shipIllegal, Model model) {
		model.addAttribute("shipIllegal", shipIllegal);
		return "modules/ship/shipIllegalForm";
	}

	@RequiresPermissions("ship:shipIllegal:edit")
	@RequestMapping(value = "save")
	public String save(ShipIllegal shipIllegal, Model model, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, shipIllegal)){
			return form(shipIllegal, model);
		}
		shipIllegalService.save(shipIllegal);
		renderStringByJbox(response, "提交成功");
		return null;
		
		//addMessage(redirectAttributes, "保存单表成功");
		//return "redirect:"+Global.getAdminPath()+"/ship/shipIllegal/?repage";
	}
	
	@RequiresPermissions("ship:shipIllegal:edit")
	@RequestMapping(value = "delete")
	public String delete(ShipIllegal shipIllegal, RedirectAttributes redirectAttributes) {
		shipIllegalService.delete(shipIllegal);
		addMessage(redirectAttributes, "删除单表成功");
		return "redirect:"+Global.getAdminPath()+"/ship/shipIllegal/?repage";
	}

}